<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        nav {
            position: relative;
            display: flex;
        }

        nav a {
            position: relative;
            text-decoration: none;
            font-size: 20px;
            color: pink;
            margin: 0 20px;
        }

        nav #maeker {
            height: 4px;
            position: absolute;
            left: 20px;
            bottom: -8px;
            transition: .5s;
            background-color: red;
        }
    </style>
</head>

<body>
    <nav>
        <div id="maeker"></div>
        <a href="#">Home</a>
        <a href="#">Home</a>
        <a href="#">Home</a>
        <a href="#">Home</a>
        <a href="#">Home</a>

    </nav>
    <script>
        var maeker = document.querySelector('#maeker');
        var dao = document.querySelectorAll('a');

        maeker.style.width = dao[0].clientWidth + "px";
        function indicator(ele) {
            maeker.style.left = ele.offsetLeft + 'px'
            maeker.style.width = ele.offsetWidth + 'px'
        }
        dao.forEach(link => {
            link.addEventListener('click', e => {
                indicator(e.target)
            })
        })
    </script>
</body>

</html>